package com.chenjiagou.ordertickets.service.impl;

import com.chenjiagou.ordertickets.entity.FlightSeat;
import com.chenjiagou.ordertickets.dao.FlightSeatDao;
import com.chenjiagou.ordertickets.service.FlightSeatService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (FlightSeat)表服务实现类
 *
 * @author makejava
 * @since 2025-06-25 16:39:47
 */
@Service("flightSeatService")
public class FlightSeatServiceImpl implements FlightSeatService {
    @Resource
    private FlightSeatDao flightSeatDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FlightSeat queryById(Long id) {
        return this.flightSeatDao.queryById(id);
    }



    /**
     * 新增数据
     *
     * @param flightSeat 实例对象
     * @return 实例对象
     */
    @Override
    public FlightSeat insert(FlightSeat flightSeat) {
        this.flightSeatDao.insert(flightSeat);
        return flightSeat;
    }

    /**
     * 修改数据
     *
     * @param flightSeat 实例对象
     * @return 实例对象
     */
    @Override
    public FlightSeat update(FlightSeat flightSeat) {
        this.flightSeatDao.update(flightSeat);
        return this.queryById(flightSeat.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.flightSeatDao.deleteById(id) > 0;
    }

    @Override
    public List<String> getAvailableSeats(Long flightId, Long seatClassId) {
        return flightSeatDao.findAvailableSeats(flightId, seatClassId);
    }

    /**
     * 将座位改为已售状态
     * @param flightId
     * @param seatNo
     */
    @Override
    public void updateByFlightAndIdNo(Long flightId, String seatNo) {
        flightSeatDao.updateByFlightAndIdNo(flightId, seatNo);
    }
}
